
package com.dps.omc.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dps.common.domain.view.BizData4Page;
import com.dps.omc.model.SubjectBizUnit;
import com.dps.omc.service.ISubjectBizUnitService;
import com.dps.common.utils.IdGenerator;
import com.dps.common.utils.JsonResult;
import com.dps.common.utils.PageParam;
import com.dps.common.utils.Constants;

@Controller
public class SubjectBizUnitAction extends AbstractAdminController<ISubjectBizUnitService>{

    @Autowired
    private ISubjectBizUnitService subjectBizUnitService;
    
    @RequestMapping(value="/subjectbizunit/list")
    public String list(SubjectBizUnit subjectBizUnit,ModelMap model,PageParam pageParam,HttpServletRequest request,HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(subjectBizUnit); 	
    	BizData4Page<SubjectBizUnit> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("subjectBizUnit", subjectBizUnit);
    	return "/module/subjectbizunit/list";
    }    
    
    @RequestMapping(value="/subjectbizunit/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("subjectBizUnit", new SubjectBizUnit());
        return "module/subjectbizunit/edit";
    }    
    
    @RequestMapping(value="/subjectbizunit/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	SubjectBizUnit subjectBizUnit = subjectBizUnitService.fetch(id);
    	model.addAttribute("subjectBizUnit", subjectBizUnit);
        return "module/subjectbizunit/edit";
    }    
    
    @RequestMapping(value="/subjectbizunit/save")
    @ResponseBody
    public String save(HttpServletRequest request,SubjectBizUnit subjectBizUnit){
		boolean isAddNew = StringUtils.isBlank(subjectBizUnit.getId())?true:false;
		if(isAddNew)
		{
			subjectBizUnit.setId(IdGenerator.createNewId());
			subjectBizUnitService.add(subjectBizUnit);
		}
		else
		{
			subjectBizUnitService.update(subjectBizUnit);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/subjectbizunit/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	subjectBizUnitService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(SubjectBizUnit subjectBizUnit)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("subjectId", subjectBizUnit.getSubjectId());		
		conditions.put("bizUnit", subjectBizUnit.getBizUnit());		
		conditions.put("createrId", subjectBizUnit.getCreaterId());		
		conditions.put("createrName", subjectBizUnit.getCreaterName());		
		conditions.put("createDate", subjectBizUnit.getCreateDate());		
    	return conditions;
    }

    @Override
    protected ISubjectBizUnitService getMainService() {
        return subjectBizUnitService;
    }

    @Override
    protected String getMainObjName() {
        return "subjectbizunit";
    }

    @Override
    protected String getViewTitle() {
        return "subjectbizunit";
    }
}
